<template>
  <div class="single">

    <el-row>
      <el-col :span="24">
        <!-- 项目 -->
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>项目</span>
          </div>
          <div class="text item">
            <el-form
              :model="p_formModel"
              :rules="p_rules"
              ref="p_formModel"
              label-width="100px"
              class="demo-p_formModel"
            >
              <!-- 项目类型 -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="项目类型" prop="xmlx">
                    <el-input v-model="p_formModel.xmlx" placeholder="请输入项目类型" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="是否是代表性成果和项目" prop="sfdbx">
                    <el-select
                      v-model="p_formModel.sfdbx"
                      placeholder="请选择是否是代表性成果和项目"
                      class="el_select">
                      <el-option
                        v-for="item in selList"
                        :label="item.name"
                        :value="item.name"
                        :key="item.val"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="项目名称" prop="xmmc">
                    <el-input v-model="p_formModel.xmmc" placeholder="请输入项目名称" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 项目批准号 -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="项目批准号" prop="xmpzh">
                    <el-input v-model="p_formModel.xmpzh" placeholder="请输入项目批准号" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="学科领域" prop="kxly">
                    <el-input v-model="p_formModel.kxly" placeholder="请输入学科领域" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="项目经费额度" prop="xmjfed">
                    <el-input v-model="p_formModel.xmjfed" placeholder="请输入项目经费额度" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 开始年月 -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="开始年月" prop="ksny">
                    <el-date-picker
                      type="date"
                      value-format="yyyy-MM-dd"
                      placeholder="请选择开始年月"
                      v-model="p_formModel.ksny"
                      style="width: 15rem"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="结束年月" prop="jsny">
                    <el-date-picker
                      type="date"
                      value-format="yyyy-MM-dd"
                      placeholder="请选择结束年月"
                      v-model="p_formModel.jsny"
                      style="width: 15rem"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="项目中本人角色" prop="drjs">
                    <el-input v-model="p_formModel.drjs" placeholder="请输入项目中本人角色" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 本人排名 -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="本人排名" prop="brpm">
                    <el-input v-model="p_formModel.brpm" placeholder="请输入本人排名" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="项目委托单位" prop="wtdw">
                    <el-input v-model="p_formModel.wtdw" placeholder="请输入项目委托单位" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="项目来源" prop="xmly">
                    <el-input v-model="p_formModel.xmly" placeholder="请输入项目来源" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row class="btns">
                <el-col :span="24">
                  <el-form-item>
                    <el-button type="primary" @click="submitForm('p_formModel')"
                    >{{ btnname }}
                    </el-button
                    >
                    <el-button @click="resetForm('p_formModel')">重置</el-button>
                  </el-form-item>
                </el-col>
              </el-row>

            </el-form>
          </div>
        </el-card>

        <!-- 著作 -->
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>著作</span>
          </div>
          <div class="text item">
            <el-form
              :model="w_formModel"
              :rules="w_rules"
              ref="w_formModel"
              label-width="110px"
              class="demo-w_formModel"
            >
              <!-- 著作类别 -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="著作类别" prop="zzlb">
                    <el-input v-model="w_formModel.zzlb" placeholder="请输入著作类别" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="是否是代表性成果和项目" prop="sfdbx">
                    <el-select
                      v-model="w_formModel.sfdbx"
                      placeholder="请选择是否是代表性成果和项目"
                      class="el_select">
                      <el-option
                        v-for="item in selList"
                        :label="item.name"
                        :value="item.name"
                        :key="item.val"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="著作名称" prop="zzmc">
                    <el-input v-model="w_formModel.zzmc" placeholder="请输入著作名称" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 项目批准号 -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="学科领域" prop="kxly">
                    <el-input v-model="w_formModel.kxly" placeholder="请输入学科领域" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="出版日期" prop="cbrq">
                    <el-date-picker
                      type="date"
                      value-format="yyyy-MM-dd"
                      placeholder="请选择出版日期"
                      v-model="w_formModel.cbrq"
                      style="width: 15rem"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="出版社名称" prop="cpsmc">
                    <el-input v-model="w_formModel.cpsmc" placeholder="请输入出版社名称" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 出版号 -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="出版号" prop="cbh">
                    <el-input v-model="w_formModel.cbh" placeholder="请输入出版号" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="著作中本人角色" prop="zzjs">
                    <el-input v-model="w_formModel.zzjs" placeholder="请输入著作中本人角色" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="总字数（字）" prop="zzs">
                    <el-input v-model="w_formModel.zzs" placeholder="请输入总字数（字）" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 本人撰写字数（字） -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="本人撰写字数（字）" prop="brzxzs">
                    <el-input v-model="w_formModel.brzxzs" placeholder="请输入本人撰写字数（字）"
                              class="el_select"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row class="btns">
                <el-col :span="24">
                  <el-form-item>
                    <el-button type="primary" @click="submitForm('w_formModel')"
                    >{{ btnname1 }}
                    </el-button
                    >
                    <el-button @click="resetForm('w_formModel')">重置</el-button>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </el-card>

        <!-- 奖励 -->
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>奖励</span>
          </div>
          <div class="text item">
            <el-form
              :model="j_formModel"
              :rules="j_rules"
              ref="j_formModel"
              label-width="100px"
              class="demo-j_formModel"
            >
              <!-- 奖励类别 -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="奖励类别" prop="jlmc">
                    <el-input v-model="j_formModel.jlmc" placeholder="请输入奖励类别" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="是否是代表性成果和项目" prop="sfdbx">
                    <el-select
                      v-model="j_formModel.sfdbx"
                      placeholder="请选择是否是代表性成果和项目"
                      class="el_select">
                      <el-option
                        v-for="item in selList"
                        :label="item.name"
                        :value="item.name"
                        :key="item.val"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="获奖年月" prop="hjny">
                    <el-date-picker
                      type="date"
                      value-format="yyyy-MM-dd"
                      placeholder="请选择获奖年月"
                      v-model="j_formModel.hjny"
                      style="width: 15rem"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 获奖名称 -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="获奖名称" prop="hjmc">
                    <el-input v-model="j_formModel.hjmc" placeholder="请输入获奖名称" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="奖励等级" prop="jldj">
                    <el-input v-model="j_formModel.jldj" placeholder="请输入奖励等级" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="奖励其他等级" prop="jlqtdj">
                    <el-input v-model="j_formModel.jlqtdj" placeholder="请输入奖励其他等级" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 本人排名 -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="本人排名" prop="brpm">
                    <el-input v-model="j_formModel.brpm" placeholder="请输入本人排名" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="授予国家（地区）" prop="sydq">
                    <el-input v-model="j_formModel.sydq" placeholder="请输入授予国家（地区）" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="授奖单位" prop="sydw">
                    <el-input v-model="j_formModel.sydw" placeholder="请输入授奖单位" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row class="btns">
                <el-col :span="24">
                  <el-form-item>
                    <el-button type="primary" @click="submitForm('j_formModel')"
                    >{{ btnname2 }}
                    </el-button
                    >
                    <el-button @click="resetForm('j_formModel')">重置</el-button>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </el-card>

        <!-- 专利或软件著作权 -->
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>专利或软件著作权</span>
          </div>
          <div class="text item">
            <el-form
              :model="r_formModel"
              :rules="r_rules"
              ref="r_formModel"
              label-width="100px"
              class="demo-r_formModel"
            >
              <!-- 奖励类别 -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="专利或软件著作权类别" prop="zllb">
                    <el-input v-model="r_formModel.zllb" placeholder="请输入专利或软件著作权类别" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="是否是代表性成果和项目" prop="sfdbx">
                    <el-select
                      v-model="r_formModel.sfdbx"
                      placeholder="请选择是否是代表性成果和项目"
                      class="el_select">
                      <el-option
                        v-for="item in selList"
                        :label="item.name"
                        :value="item.name"
                        :key="item.val"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="批准日期" prop="pzrq">
                    <el-date-picker
                      type="date"
                      value-format="yyyy-MM-dd"
                      placeholder="请选择批准日期"
                      v-model="r_formModel.pzrq"
                      style="width: 15rem"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 获奖名称 -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="专利或软件著作权名称" prop="zlmc">
                    <el-input v-model="r_formModel.zlmc" placeholder="请输入专利或软件著作权名称"
                              class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="学科领域" prop="kxly">
                    <el-input v-model="r_formModel.kxly" placeholder="请输入学科领域" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="本人角色" prop="brjs">
                    <el-input v-model="r_formModel.brjs" placeholder="请输入本人角色" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 专利号（登记号） -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="专利号（登记号）" prop="zlh">
                    <el-input v-model="r_formModel.zlh" placeholder="请输入专利号（登记号）" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row class="btns">
                <el-col :span="24">
                  <el-form-item>
                    <el-button type="primary" @click="submitForm('r_formModel')"
                    >{{ btnname3 }}
                    </el-button
                    >
                    <el-button @click="resetForm('r_formModel')">重置</el-button>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </el-card>

        <!-- 报告 -->
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>报告</span>
          </div>
          <div class="text item">
            <el-form
              :model="b_formModel"
              :rules="b_rules"
              ref="b_formModel"
              label-width="100px"
              class="demo-b_formModel"
            >
              <!-- 奖励类别 -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="报告题目" prop="bgtm">
                    <el-input v-model="b_formModel.bgtm" placeholder="请输入报告题目" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="是否是代表性成果和项目" prop="sfdbx">
                    <el-select
                      v-model="b_formModel.sfdbx"
                      placeholder="请选择是否是代表性成果和项目"
                      class="el_select">
                      <el-option
                        v-for="item in selList"
                        :label="item.name"
                        :value="item.name"
                        :key="item.val"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="报告时间" prop="bgsj">
                    <el-date-picker
                      type="date"
                      placeholder="请选报告时间"
                      value-format="yyyy-MM-dd"
                      v-model="b_formModel.bgsj"
                      style="width: 15rem"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- 获奖名称 -->
              <el-row>
                <el-col :span="8">
                  <el-form-item label="本人角色" prop="brjs">
                    <el-input v-model="b_formModel.brjs" placeholder="请输入本人角色" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="委托方" prop="wtf">
                    <el-input v-model="b_formModel.wtf" placeholder="请输入委托方" class="el_select"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row class="btns">
                <el-col :span="24">
                  <el-form-item>
                    <el-button type="primary" @click="submitForm('b_formModel')"
                    >{{ btnname4 }}
                    </el-button
                    >
                    <el-button @click="resetForm('b_formModel')">重置</el-button>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'studyexp',
  data () {
    return {
      cityList: [
        {name: '中国', val: 0},
        {name: '香港', val: 1},
      ],
      educationList: [
        {name: '小学', val: 0},
        {name: '大学', val: 1},
      ],
      schoolList: [
        {name: 'xxx学院', val: 0},
        {name: 'xxx学院', val: 1},
      ],
      selList: [
        {name: '否', val: 0},
        {name: '是', val: 1},
      ],

      // 项目
      p_formModel: {
        jsId: '',
        xmlx: '',
        sfdbx: '',
        xmmc: '',
        xmpzh: '',
        kxly: '',
        xmjfed: '',
        ksny: '',
        jsny: '',
        drjs: '',
        brpm: '',
        xmly: '',
      },
      p_rules: {
        xmlx: [
          {required: true, message: '请输入项目类型', trigger: 'blur'},
        ],
        sfdbx: [
          {required: true, message: '请选择是否是代表性成果和项目', trigger: 'change'},
        ],
        xmmc: [
          {required: true, message: '请输入项目名称', trigger: 'blur'},
        ],
        xmpzh: [
          {required: true, message: '请输入项目批准号', trigger: 'blur'},
        ],
        kxly: [
          {required: true, message: '请输入学科领域', trigger: 'blur'},
        ],
        xmjfed: [
          {required: true, message: '请输入项目经费额度', trigger: 'blur'},
        ],
        ksny: [
          {
            type: 'string', required: true, message: '请选择开始年月', trigger: 'change',
          },
        ],
        jsny: [
          {
            type: 'string', required: true, message: '请选择结束年月', trigger: 'change',
          },
        ],
        drjs: [
          {required: true, message: '请输入项目中本人角色', trigger: 'blur'},
        ],
        brpm: [
          {required: true, message: '请输入本人排名', trigger: 'blur'},
        ],
        wtdw: [
          {required: true, message: '请输入项目委托单位', trigger: 'blur'},
        ],
        xmly: [
          {required: true, message: '请输入项目来源', trigger: 'blur'},
        ]
      },
      // 著作
      w_formModel: {
        jsId: '',
        zzlb: '',
        sfdbx: '',
        zzmc: '',
        kxly: '',
        cbrq: '',
        cpsmc: '',
        cbh: '',
        zzjs: '',
        zzs: '',
        brzxzs: ''
      },
      w_rules: {
        zzlb: [
          {required: true, message: '请输入著作类别', trigger: 'blur'},
        ],
        sfdbx: [
          {required: true, message: '请选择是否是代表性成果和项目', trigger: 'change'},
        ],
        zzmc: [
          {required: true, message: '请输入著作名称', trigger: 'blur'},
        ],
        cpsmc: [
          {required: true, message: '请输入著作名称', trigger: 'blur'},
        ],
        kxly: [
          {required: true, message: '请输入学科领域', trigger: 'blur'},
        ],
        reelnumber: [
          {required: true, message: '请输入卷号', trigger: 'blur'},
        ],
        cbrq: [
          {required: true, message: '请输入出版日期', trigger: 'blur'},
        ],
        cbh: [
          {required: true, message: '请输入出版号', trigger: 'blur'},
        ],
        zzjs: [
          {required: true, message: '请输入著作中本人角色', trigger: 'blur'},
        ],
        zzs: [
          {required: true, message: '请输入著作总字数', trigger: 'blur'},
        ],
        brzxzs: [
          {required: true, message: '请输入著作中本人撰写字数', trigger: 'blur'},
        ],
      },
      // 奖励
      j_formModel: {
        jsId: '',
        jlmc: '',
        sfdbx: '',
        hjny: '',
        hjmc: '',
        hjdj: '',
        jldj: '',
        jlqtdj: '',
        brpm: '',
        sydq: '',
        sydw: '',
      },
      j_rules: {
        jlmc: [
          {required: true, message: '请输入奖励类别', trigger: 'blur'},
        ],
        sfdbx: [
          {required: true, message: '请选择是否是代表性成果和项目', trigger: 'change'},
        ],
        hjny: [
          {
            type: 'string', required: true, message: '请选择获奖年月', trigger: 'change',
          },
        ],
        hjmc: [
          {required: true, message: '请输入获奖名称', trigger: 'blur'},
        ],
        jldj: [
          {required: true, message: '请输入奖励等级', trigger: 'blur'},
        ],
        jlqtdj: [
          {required: true, message: '请输入奖励其他等级', trigger: 'blur'},
        ],
        brpm: [
          {required: true, message: '请输入本人排名', trigger: 'blur'},
        ],
        sydq: [
          {required: true, message: '请输入授予国家（地区）', trigger: 'blur'},
        ],
        dydw: [
          {required: true, message: '请输入授奖单位', trigger: 'blur'},
        ]
      },
      // 专利或软件著作权
      r_formModel: {
        jsId: '',
        zllb: '',
        sfdbx: '',
        pzrq: '',
        zlmc: '',
        kxly: '',
        brjs: '',
        zlh: '',
      },
      r_rules: {
        zllb: [
          {required: true, message: '请输入专利或软件著作权类别', trigger: 'blur'},
        ],
        sfdbx: [
          {required: true, message: '请选择是否是代表性成果和项目', trigger: 'change'},
        ],
        pzrq: [
          {
            type: 'string', required: true, message: '请选择批准日期', trigger: 'change',
          },
        ],
        zlmc: [
          {required: true, message: '请输入专利或软件著作权名称', trigger: 'blur'},
        ],
        kxly: [
          {required: true, message: '请输入学科领域', trigger: 'blur'},
        ],
        brjs: [
          {required: true, message: '请输入本人角色', trigger: 'blur'},
        ],
        zlh: [
          {required: true, message: '请输入专利号（登记号）', trigger: 'blur'},
        ],
      },
      // 报告
      b_formModel: {
        jsId: '',
        bgtm: '',
        sfdbx: '',
        bgsj: '',
        brjs: '',
        wtf: '',
      },
      b_rules: {
        bgtm: [
          {required: true, message: '请输入报告题目', trigger: 'blur'},
        ],
        sfdbx: [
          {required: true, message: '请选择是否是代表性成果和项目', trigger: 'change'},
        ],
        bgsj: [
          {
            type: 'string', required: true, message: '请选报告时间', trigger: 'change',
          }
        ],
        brjs: [
          {required: true, message: '请输入本人角色', trigger: 'blur'},
        ],
        wtf: [
          {required: true, message: '请输入委托方', trigger: 'blur'},
        ],

      },
      btnname: '添加',
      btnname1: '添加',
      btnname2: '添加',
      btnname3: '添加',
      btnname4: '添加',
      page: {
        id: '',
        op: 'add'
      },
      page1: {
        id: '',
        op: 'add'
      },
      page2: {
        id: '',
        op: 'add'
      },
      page3: {
        id: '',
        op: 'add'
      },
      page4: {
        id: '',
        op: 'add'
      }
    }
  },
  mounted () {
    this.initdata()
  },
  methods: {
    initdata () {
      var params = this.$route.params
      console.log(params)
      this.page.id = params.id
      this.page.op = params.op
      this.get_detail()
    },
    get_detail () {
      var params = {jsId: this.page.id}
      // 项目
      this.$http({
        url: this.$http.adornUrl('/xmcg/getJsXmcg'),
        method: 'get',
        params: this.$http.adornParams(params)
      }).then(({data}) => {
        console.log(data.data)
        if (data && data.code === 0) {
          if (data.data.length > 0) {
            this.page.op = 'detail'
            this.btnname = '修改'
            this.p_formModel = data.data[0]
          } else {
            this.page.op = 'add'
            this.btnname = '添加'
          }
        } else {
          this.$message.error(data.msg)
        }
      })
      // 著作
      this.$http({
        url: this.$http.adornUrl('/zzcg/getJsZzcg'),
        method: 'get',
        params: this.$http.adornParams(params)
      }).then(({data}) => {
        console.log(data.data)
        if (data && data.code === 0) {
          if (data.data.length > 0) {
            this.page1.op = 'detail'
            this.btnname1 = '修改'
            this.w_formModel = data.data[0]
          } else {
            this.page1.op = 'add'
            this.btnname = '添加'
          }
        } else {
          this.$message.error(data.msg)
        }
      })
      // 奖励
      this.$http({
        url: this.$http.adornUrl('/jlcg/getJsAllJlcg'),
        method: 'get',
        params: this.$http.adornParams(params)
      }).then(({data}) => {
        console.log(data.data)
        if (data && data.code === 0) {
          if (data.data.length > 0) {
            this.page2.op = 'detail'
            this.btnname2 = '修改'
            this.j_formModel = data.data[0]
          } else {
            this.page2.op = 'add'
            this.btnname = '添加'
          }
        } else {
          this.$message.error(data.msg)
        }
      })
      // 专利
      this.$http({
        url: this.$http.adornUrl('/zlcg/getJsZlcg'),
        method: 'get',
        params: this.$http.adornParams(params)
      }).then(({data}) => {
        console.log(data.data)
        if (data && data.code === 0) {
          if (data.data.length > 0) {
            this.page3.op = 'detail'
            this.btnname3 = '修改'
            this.r_formModel = data.data[0]
          } else {
            this.page3.op = 'add'
            this.btnname = '添加'
          }
        } else {
          this.$message.error(data.msg)
        }
      })
      // 报告
      this.$http({
        url: this.$http.adornUrl('/bgcg/getJsAllBgcg'),
        method: 'get',
        params: this.$http.adornParams(params)
      }).then(({data}) => {
        console.log(data.data)
        if (data && data.code === 0) {
          if (data.data.length > 0) {
            this.page4.op = 'detail'
            this.btnname3 = '修改'
            this.b_formModel = data.data[0]
          } else {
            this.page4.op = 'add'
            this.btnname = '添加'
          }
        } else {
          this.$message.error(data.msg)
        }
      })
    },
    submitForm (formName) {
      let jsId = this.$store.state.user.jsid
      let formModel = {}
      let url = ''
      switch (formName) {
        case 'p_formModel':
          if (this.page.op == 'add') {
            url = '/xmcg/save'
          } else {
            url = '/xmcg/update'
          }
          formModel = this.p_formModel
          break
        case 'w_formModel':
          formModel = this.w_formModel
          if (this.page1.op == 'add') {
            url = '/zzcg/save'
          } else {
            url = '/zzcg/update'
          }
          break
        case 'j_formModel':
          formModel = this.j_formModel
          if (this.page2.op == 'add') {
            url = '/jlcg/save'
          } else {
            url = '/jlcg/update'
          }
          break
        case 'r_formModel':
          formModel = this.r_formModel
          if (this.page3.op == 'add') {
            url = '/zlcg/save'
          } else {
            url = '/zlcg/update'
          }
          break
        case 'b_formModel':
          formModel = this.b_formModel
          if (this.page4.op == 'add') {
            url = '/bgcg/save'
          } else {
            url = '/bgcg/update'
          }
          break
      }
      formModel.jsId = jsId
      let formData = this.get_formdata(formModel)
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(url),
            data: formData,
            method: 'post'
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    },
    get_formdata (config) {
      console.log(config)
      //对象转formdata格式
      const formData = new FormData()
      //循环传入的值转换formData
      Object.keys(config).forEach((key) => {
        formData.append(key, config[key])
      })
      return formData
    },
  },
}
</script>


<style>
.single {
  padding: 0.5rem;
}

.el_select {
  width: 15rem;
}

.btns {
  padding-left: 22rem;
}

.item {
  padding: 0.5rem 0px;
}
</style>

